<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<input type="file" id="put">
<script>
    var put=document.getElementById("put");
    put.onchange=function () {
        var filename=put.value
        var houzhui=filename.substr(filename.lastIndexOf(".")).toUpperCase();
        if (houzhui===".JPG"||houzhui===".PNG"){
            alert("格式正确");
        } else {
            alert("格式错误");
        }
    }
</script>
</body>
</html>